package com.shen.JUC.Lock8;

import java.util.concurrent.TimeUnit;

public class Lock3 {
    /*5.两个静态方法谁先执行
    答：synchronized  锁的对象是方法的调用者
        static  类一加载就有了，锁的是整个Class类，
        6.如果存在两个对象，先执行哪个
        两个对象类模板也就只有一个，执行第一个
    * */
    public static void main(String[] args) throws InterruptedException {
        Phone3 phone = new Phone3();

        new Thread(() -> {
            try {
                phone.sell();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "A").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(() -> {
            phone.call();
        }, "B").start();
    }
}

class Phone3 {
    public static synchronized void sell() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        System.out.println("sell message");
    }

    public static synchronized void call() {
        System.out.println("call phone");
    }


}